home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / man / catn / bind.n < prev    next >
Text File  |  1994-09-20  |  20KB  |  529 lines

  1.  
  2.  
  3.  
  4. bind(n)                    Tk Commands
  5.  
  6.  
  7.  
  8. _________________________________________________________________
  9.  
  10. NAME
  11.      bind - Arrange for X events to invoke Tcl commands
  12.  
  13. SYNOPSIS
  14.      bind _w_i_n_d_o_w_S_p_e_c
  15.      bind _w_i_n_d_o_w_S_p_e_c _s_e_q_u_e_n_c_e
  16.      bind _w_i_n_d_o_w_S_p_e_c _s_e_q_u_e_n_c_e _c_o_m_m_a_n_d
  17.      bind _w_i_n_d_o_w_S_p_e_c _s_e_q_u_e_n_c_e +_c_o_m_m_a_n_d
  18. _________________________________________________________________
  19.  
  20.  
  21. DESCRIPTION
  22.      If all three arguments are specified, bind will arrange  for
  23.      _c_o_m_m_a_n_d (a Tcl command) to be executed whenever the sequence
  24.      of events given by _s_e_q_u_e_n_c_e occurs in the window(s)  identi-  |
  25.      fied  by  _w_i_n_d_o_w_S_p_e_c.   If _c_o_m_m_a_n_d is prefixed with a ``+'',
  26.      then it is appended to any existing  binding  for  _s_e_q_u_e_n_c_e;
  27.      otherwise _c_o_m_m_a_n_d replaces the existing binding, if any.  If
  28.      _c_o_m_m_a_n_d is an empty string  then  the  current  binding  for
  29.      _s_e_q_u_e_n_c_e  is destroyed, leaving _s_e_q_u_e_n_c_e unbound.  In all of
  30.      the cases where a _c_o_m_m_a_n_d argument is provided, bind returns
  31.      an empty string.
  32.  
  33.      If _s_e_q_u_e_n_c_e is specified without a _c_o_m_m_a_n_d, then the command
  34.      currently  bound to _s_e_q_u_e_n_c_e is returned, or an empty string
  35.      if there is no binding for _s_e_q_u_e_n_c_e.   If  neither  _s_e_q_u_e_n_c_e
  36.      nor  _c_o_m_m_a_n_d  is  specified, then the return value is a list
  37.      whose elements are all the sequences for which  there  exist  |
  38.      bindings for _w_i_n_d_o_w_S_p_e_c.                                      |
  39.  
  40.      The _w_i_n_d_o_w_S_p_e_c argument selects which window(s) the  binding  |
  41.      applies  to.  It may have one of three forms.  If _w_i_n_d_o_w_S_p_e_c  |
  42.      is the path name for a window, then the binding  applies  to  |
  43.      that  particular  window.   If  _w_i_n_d_o_w_S_p_e_c  is the name of a  |
  44.      class of widgets, then the binding applies to all widgets in  |
  45.      that  class.   Lastly, _w_i_n_d_o_w_S_p_e_c may have the value all, in  |
  46.      which case the binding applies to all windows in the  appli-  |
  47.      cation.
  48.  
  49.      The _s_e_q_u_e_n_c_e argument specifies a sequence of  one  or  more
  50.      event  patterns,  with optional white space between the pat-
  51.      terns.  Each event pattern may take either of two forms.  In
  52.      the  simplest  case it is a single printing ASCII character,
  53.      such as a or [.  The character may not be a space  character
  54.      or the character <.  This form of pattern matches a KeyPress
  55.      event for the particular character.  The second form of pat-
  56.      tern  is longer but more general.  It has the following syn-
  57.      tax:
  58.  
  59.           <_m_o_d_i_f_i_e_r-_m_o_d_i_f_i_e_r-_t_y_p_e-_d_e_t_a_i_l>
  60.  
  61.  
  62.  
  63. Tk                                                              1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. bind(n)                    Tk Commands
  71.  
  72.  
  73.  
  74.      The entire event pattern is surrounded  by  angle  brackets.
  75.      Inside  the  angle  brackets  are zero or more modifiers, an
  76.      event type, and an extra piece of information (_d_e_t_a_i_l) iden-
  77.      tifying  a  particular  button or keysym.  Any of the fields
  78.      may be omitted, as long as at least one of _t_y_p_e  and  _d_e_t_a_i_l
  79.      is  present.  The fields must be separated by white space or
  80.      dashes.
  81.  
  82.      Modifiers may consist of any of the values in the  following
  83.      list:
  84.  
  85.           Control                 Any
  86.           Shift                   Double
  87.           Lock                    Triple
  88.           Button1, B1             Mod1, M1, Meta, M                |
  89.           Button2, B2             Mod2, M2, Alt                    |
  90.           Button3, B3             Mod3, M3
  91.           Button4, B4             Mod4, M4
  92.           Button5, B5             Mod5, M5
  93.  
  94.      Where more than one value is listed,  separated  by  commas,
  95.      the  values  are  equivalent.    All of the modifiers except
  96.      Any, Double, and Triple have the obvious  X  meanings.   For
  97.      example,  Button1  requires  that button 1 be depressed when
  98.      the event occurs.  Under normal conditions  the  button  and
  99.      modifier  state  at the time of the event must match exactly
  100.      those specified in the bind command.  If  no  modifiers  are
  101.      specified,  then  events will match only if no modifiers are
  102.      present.  If the Any modifier is specified, then  additional
  103.      modifiers may be present besides those specified explicitly.
  104.      For example, if button 1 is pressed while the shift and con-
  105.      trol  keys  are  down,  the specifier <Any-Control-Button-1>
  106.      will match the event, but the  specifier  <Control-Button-1>
  107.      will not.
  108.  
  109.      The Double and Triple modifiers are a convenience for speci-
  110.      fying  double  mouse  clicks and other repeated events. They
  111.      cause a particular event pattern  to  be  repeated  2  or  3
  112.      times,  and  also  place a time and space requirement on the
  113.      sequence:  for a sequence of events to  match  a  Double  or
  114.      Triple  pattern, all of the events must occur close together
  115.      in time and without substantial  mouse  motion  in  between.
  116.      For  example,  <Double-Button-1>  is  equivalent to <Button-
  117.      1><Button-1> with the extra time and space requirement.
  118.  
  119.      The _t_y_p_e field may be any of the  standard  X  event  types,
  120.      with  a few extra abbreviations.  Below is a list of all the
  121.      valid types;  where  two  name  appear  together,  they  are
  122.      synonyms.
  123.  
  124.           ButtonPress, Button Expose             Leave
  125.           ButtonRelease       FocusIn            Map
  126.           Circulate           FocusOut           Property
  127.  
  128.  
  129.  
  130. Tk                                                              2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. bind(n)                    Tk Commands
  137.  
  138.  
  139.  
  140.           CirculateRequest    Gravity            Reparent
  141.           Colormap            Keymap             ResizeRequest
  142.           Configure           KeyPress, Key      Unmap
  143.           ConfigureRequest    KeyRelease         Visibility        |
  144.           Destroy             MapRequest
  145.           Enter               Motion
  146.  
  147.  
  148.      The last part of a long event specification is  _d_e_t_a_i_l.   In
  149.      the  case of a ButtonPress or ButtonRelease event, it is the
  150.      number of a button (1-5).  If a button number is given, then
  151.      only  an  event on that particular button will match;  if no
  152.      button number is given, then an event  on  any  button  will
  153.      match.   Note:  giving a specific button number is different
  154.      than specifying a button modifier; in  the  first  case,  it
  155.      refers  to  a button being pressed or released, while in the
  156.      second it refers  to  some  other  button  that  is  already
  157.      depressed  when  the  matching  event  occurs.   If a button
  158.      number is given then _t_y_p_e may be omitted:  if  will  default
  159.      to   ButtonPress.    For   example,  the  specifier  <1>  is
  160.      equivalent to <ButtonPress-1>.
  161.  
  162.      If the event type is KeyPress or KeyRelease, then _d_e_t_a_i_l may
  163.      be  specified  in the form of an X keysym.  Keysyms are tex-
  164.      tual specifications for particular  keys  on  the  keyboard;
  165.      they  include  all  the  alphanumeric ASCII characters (e.g.
  166.      ``a'' is the keysym for the  ASCII  character  ``a''),  plus
  167.      descriptions  for  non-alphanumeric characters (``comma'' is
  168.      the keysym for the comma character), plus  descriptions  for
  169.      all  the  non-ASCII keys on the keyboard (``Shift_L'' is the
  170.      keysm for the left shift key, and ``F1'' is the  keysym  for
  171.      the  F1  function  key, if it exists).  The complete list of
  172.      keysyms is not presented here;  it should  be  available  in
  173.      other  X  documentation.   If  necessary, you can use the %K
  174.      notation described below to print out the keysym name for an
  175.      arbitrary  key.   If a keysym _d_e_t_a_i_l is given, then the _t_y_p_e
  176.      field may be omitted;  it will  default  to  KeyPress.   For
  177.      example,   <Control-comma>   is   equivalent   to  <Control-
  178.      KeyPress-comma>.  If a keysym _d_e_t_a_i_l is specified  then  the
  179.      Shift  modifier need not be specified and will be ignored if
  180.      specified:  each keysym already implies a  particular  state
  181.      for the shift key.
  182.  
  183.      The _c_o_m_m_a_n_d argument to bind is a Tcl command string,  which
  184.      will  be  executed whenever the given event sequence occurs.
  185.      _C_o_m_m_a_n_d will be executed in the same  interpreter  that  the
  186.      bind  command  was  executed  in.  If _c_o_m_m_a_n_d contains any %
  187.      characters, then the command string  will  not  be  executed
  188.      directly.   Instead,  a new command string will be generated
  189.      by replacing each %, and the character  following  it,  with
  190.      information from the current event.  The replacement depends
  191.      on the character following the %, as  defined  in  the  list
  192.      below.   Unless  otherwise indicated, the replacement string  |
  193.  
  194.  
  195.  
  196. Tk                                                              3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. bind(n)                    Tk Commands
  203.  
  204.  
  205.  
  206.      is the decimal value of the given  field  from  the  current  |
  207.      event.  Some of the substitutions are only valid for certain
  208.      types of events;  if they are used for other types of events
  209.      the value substituted is undefined.
  210.  
  211.      %%   Replaced with a single percent.
  212.  
  213.      %#   The number of the last client request processed by  the
  214.           server  (the  _s_e_r_i_a_l  field from the event).  Valid for
  215.           all event types.
  216.  
  217.      %a   The _a_b_o_v_e field from the event.  Valid only for  Confi-
  218.           gureNotify events.
  219.  
  220.      %b   The number of the button that was pressed or  released.
  221.           Valid only for ButtonPress and ButtonRelease events.
  222.  
  223.      %c   The _c_o_u_n_t field from the event.  Valid only for Expose,
  224.           GraphicsExpose, and MappingNotify events.
  225.  
  226.      %d   The _d_e_t_a_i_l field from the event.  The %d is replaced by
  227.           a  string  identifying  the  detail.   For EnterNotify,
  228.           LeaveNotify, FocusIn, and FocusOut events,  the  string
  229.           will be one of the following:
  230.  
  231.                NotifyAncestor          NotifyNonlinearVirtual
  232.                NotifyDetailNone        NotifyPointer
  233.                NotifyInferior          NotifyPointerRoot
  234.                NotifyNonlinear         NotifyVirtual
  235.  
  236.           For ConfigureRequest  events,  the  substituted  string
  237.           will be one of the following:
  238.  
  239.                Above                   Opposite
  240.                Below                   TopIf
  241.                BottomIf
  242.           For events other than these, the substituted string  is
  243.           undefined.
  244.  
  245.      %f   The _f_o_c_u_s field from the event (0 or  1).   Valid  only
  246.           for EnterNotify and LeaveNotify events.
  247.  
  248.      %h   The _h_e_i_g_h_t field from the event.  Valid only  for  Con-
  249.           figure,  ConfigureNotify,  Expose,  GraphicsExpose, and
  250.           ResizeRequest events.
  251.  
  252.      %k   The _k_e_y_c_o_d_e field  from  the  event.   Valid  only  for
  253.           KeyPress and KeyRelease events.
  254.  
  255.      %m   The _m_o_d_e field from the event.  The substituted  string
  256.           is  one  of  NotifyNormal, NotifyGrab, NotifyUngrab, or
  257.           NotifyWhileGrabbed.   Valid   only   for   EnterWindow,
  258.  
  259.  
  260.  
  261. Tk                                                              4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. bind(n)                    Tk Commands
  269.  
  270.  
  271.  
  272.           FocusIn, FocusOut, and LeaveWindow events.
  273.  
  274.      %o   The _o_v_e_r_r_i_d_e__r_e_d_i_r_e_c_t field from the event.  Valid only
  275.           for CreateNotify, MapNotify, ReparentNotify, and Confi-
  276.           gureNotify events.
  277.  
  278.      %p   The _p_l_a_c_e field from the event, substituted as  one  of
  279.           the  strings  PlaceOnTop  or PlaceOnBottom.  Valid only
  280.           for CirculateNotify and CirculateRequest events.
  281.  
  282.      %s   The _s_t_a_t_e field from the event.  For ButtonPress,  But-
  283.           tonRelease, EnterNotify, KeyPress, KeyRelease, LeaveNo-
  284.           tify, and MotionNotify events, a decimal string is sub-  |
  285.           stituted.   For  VisibilityNotify,  one  of the strings
  286.           VisibilityUnobscured, VisibilityPartiallyObscured,  and
  287.           VisibilityFullyObscured is substituted.
  288.  
  289.      %t   The _t_i_m_e field from the event.  Valid only  for  events
  290.           that contain a _t_i_m_e field.
  291.  
  292.      %v   The _v_a_l_u_e__m_a_s_k field from the event.   Valid  only  for
  293.           ConfigureRequest events.
  294.  
  295.      %w   The _w_i_d_t_h field from the event.  Valid only for Config-
  296.           ure,   ConfigureRequest,  Expose,  GraphicsExpose,  and
  297.           ResizeRequest events.
  298.  
  299.      %x   The _x field from the event.  Valid only for events con-
  300.           taining an _x field.
  301.  
  302.      %y   The _y field from the event.  Valid only for events con-
  303.           taining a _y field.
  304.  
  305.      %A   Substitutes the ASCII character  corresponding  to  the
  306.           event,  or  the  empty  string  if  the  event  doesn't
  307.           correspond to an ASCII character (e.g.  the  shift  key
  308.           was  pressed).   XLookupString  does  all  the  work of
  309.           translating from  the  event  to  an  ASCII  character.
  310.           Valid only for KeyPress and KeyRelease events.
  311.  
  312.      %B   The _b_o_r_d_e_r__w_i_d_t_h field from the event.  Valid only  for
  313.           ConfigureNotify and CreateWindow events.
  314.  
  315.      %D   The _d_i_s_p_l_a_y field from the event.  Valid for all  event
  316.           types.
  317.  
  318.      %E   The _s_e_n_d__e_v_e_n_t field from the  event.   Valid  for  all
  319.           event types.
  320.  
  321.      %K   The keysym corresponding to the event, substituted as a
  322.           textual string.  Valid only for KeyPress and KeyRelease
  323.           events.
  324.  
  325.  
  326.  
  327. Tk                                                              5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. bind(n)                    Tk Commands
  335.  
  336.  
  337.  
  338.      %N   The keysym corresponding to the event, substituted as a  |
  339.           decimal number.  Valid only for KeyPress and KeyRelease
  340.           events.
  341.  
  342.      %R   The _r_o_o_t window identifier from the event.  Valid  only
  343.           for events containing a _r_o_o_t field.
  344.  
  345.      %S   The _s_u_b_w_i_n_d_o_w window identifier from the event.   Valid
  346.           only for events containing a _s_u_b_w_i_n_d_o_w field.
  347.  
  348.      %T   The _t_y_p_e field from the event.   Valid  for  all  event
  349.           types.
  350.  
  351.      %W   The path name of the window  to  which  the  event  was
  352.           reported  (the _w_i_n_d_o_w field from the event).  Valid for
  353.           all event types.
  354.  
  355.      %X   The _x__r_o_o_t field from the  event.   If  a  virtual-root  |
  356.           window manager is being used then the substituted value  |
  357.           is the corresponding x-coordinate in the virtual  root.
  358.           Valid  only  for  ButtonPress, ButtonRelease, KeyPress,
  359.           KeyRelease, and MotionNotify events.
  360.  
  361.      %Y   The _y__r_o_o_t field from the  event.   If  a  virtual-root  |
  362.           window manager is being used then the substituted value  |
  363.           is the corresponding y-coordinate in the virtual  root.
  364.           Valid  only  for  ButtonPress, ButtonRelease, KeyPress,
  365.           KeyRelease, and MotionNotify events.
  366.  
  367.      If the replacement string for a %-replacement contains char-  |
  368.      acters  that  are  interpreted  specially  by the Tcl parser  |
  369.      (such as backslashes or square  brackets  or  spaces)  addi-  |
  370.      tional  backslashes are added during replacement so that the  |
  371.      result after parsing is  the  original  replacement  string.  |
  372.      For example, if _c_o_m_m_a_n_d is                                    |
  373.  
  374.           insert %A                                                |
  375.  
  376.      and the character typed is an open square bracket, then  the  |
  377.      command actually executed will be                             |
  378.  
  379.           insert \[                                                |
  380.      This will cause the insert to receive the original  replace-  |
  381.      ment string (open square bracket) as its first argument.  If  |
  382.      the extra backslash hadn't been added, Tcl  would  not  have  |
  383.      been able to parse the command correctly.
  384.  
  385.      At most one binding will trigger for any given X event.   If
  386.      several  bindings match the recent events, the most specific
  387.      binding is chosen and its command  will  be  executed.   The
  388.      following tests are applied, in order, to determine which of
  389.      several matching sequences is more specific: (a)  a  binding  |
  390.  
  391.  
  392.  
  393. Tk                                                              6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. bind(n)                    Tk Commands
  401.  
  402.  
  403.  
  404.      whose  _w_i_n_d_o_w_S_p_e_c names a particular window is more specific  |
  405.      than a binding for a class, which is more  specific  than  a  |
  406.      binding  whose  _w_i_n_d_o_w_S_p_e_c is all; (b) a longer sequence (in
  407.      terms of number of events matched) is more specific  than  a
  408.      shorter  sequence;  (c)  an  event  pattern that specifies a
  409.      specific button or  key  is  more  specific  than  one  that
  410.      doesn't;   (e)  an  event pattern that requires a particular
  411.      modifier is more specific than one that doesn't require  the
  412.      modifier;  (e)  an event pattern specifying the Any modifier
  413.      is less specific than one that  doesn't.   If  the  matching
  414.      sequences  contain  more  than one event, then tests (c)-(e)
  415.      are applied in order from the most recent event to the least
  416.      recent  event  in  the  sequences.   If  these tests fail to
  417.      determine  a  winner,  then  the  most  recently  registered
  418.      sequence is the winner.
  419.  
  420.      If an X event does not match any of the  existing  bindings,
  421.      then  the  event  is  ignored  (an unbound event is not con-
  422.      sidered to be an error).
  423.  
  424.      When a _s_e_q_u_e_n_c_e specified in a bind  command  contains  more
  425.      than  one  event pattern, then its command is executed when-
  426.      ever the recent events (leading  up  to  and  including  the
  427.      current  event)  match  the given sequence.  This means, for
  428.      example, that if button 1 is clicked repeatedly the sequence
  429.      <Double-ButtonPress-1>  will match each button press but the
  430.      first.  If extraneous events  that  would  prevent  a  match  |
  431.      occur in the middle of an event sequence then the extraneous  |
  432.      events are ignored unless they are KeyPress  or  ButtonPress  |
  433.      events.   For  example,  <Double-ButtonPress-1> will match a  |
  434.      sequence of presses of button 1, even though there  will  be  |
  435.      ButtonRelease  events  (and  possibly  MotionNotify  events)  |
  436.      between the ButtonPress  events.   Furthermore,  a  KeyPress  |
  437.      event may be preceded by any number of other KeyPress events  |
  438.      for modifier keys without the  modifier  keys  preventing  a  |
  439.      match.   For  example,  the  event  sequence aB will match a  |
  440.      press of the a key, a release of the a key, a press  of  the  |
  441.      Shift  key, and a press of the b key:  the press of Shift is  |
  442.      ignored because it is a modifier key.  Finally,  if  several
  443.      MotionNotify  events  occur  in  a row, only the last one is
  444.      used for purposes of matching binding sequences.
  445.  
  446.      If an error occurs in executing the command  for  a  binding
  447.      then the tkerror mechanism is used to report the error.  The  |
  448.      command will be executed at global level (outside  the  con-  |
  449.      text of any Tcl procedure).
  450.  
  451.  
  452. SEE ALSO
  453.      tkerror
  454.  
  455.  
  456.  
  457.  
  458.  
  459. Tk                                                              7
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. bind(n)                    Tk Commands
  467.  
  468.  
  469.  
  470. KEYWORDS
  471.      form, manual
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. Tk                                                              8
  526.  
  527.  
  528.  
  529.